import { InterceptorManager } from "../lib/core/interceptor"
import { CancelToken } from "../lib/cancel"


export interface AxiosOption {
  url:string
  method:string
  baseURL?:string
  transformRequest?():unknown
  transformResponse?():unknown
  headers?:object
  params?:object
  paramsSerializer?(params:object):string
  data?:object
  timeout?:number
  withCredentials?:boolean
  responseType?:'json'|'text'
  responseEncoding?:'utf-8'|'gbk'
  onUploadProgress?(ev:ProgressEvent):void
  onDownloadProgress?(ev:ProgressEvent):void
  validateStatus?(status:number):boolean
  proxy?:{
    protocol:'https'|'http'
    host:string
    port:number
  }
  cancelToken?:CancelToken
  adapter?():void
}

export interface AxiosResponse {
  config: {
    url:string
    method:string
  }
  data:unknown
  headers:object
  request: XMLHttpRequest
  status:number
  statusText:string
}

export interface AxiosFactoryInstance {
  (opt:AxiosOption):Promise<AxiosResponse>
  (url:string, opt:AxiosOption):Promise<AxiosResponse>
  request(opt:AxiosOption):Promise<AxiosResponse>
  get():Promise<AxiosResponse>
  post():Promise<AxiosResponse>
  put():Promise<AxiosResponse>
  patch():Promise<AxiosResponse>
  delete():Promise<AxiosResponse>
  defaults:object
  interceptors:{
    request:InterceptorManager
    response:InterceptorManager
  }
}

export interface AxiosInstance extends AxiosFactoryInstance {
  create(opt:AxiosOption):AxiosFactoryInstance
  all():void

}